home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / jovept2.arc / TD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-05-30  |  5.0 KB  |  285 lines

  1. /* td.c */
  2.  
  3. /* simplified screen driver for jove. */
  4. /* JOVE/MSDOS. K. Mitchum 1/85 */
  5. /* Ken Mitchum */
  6. /* University of Pittsburgh */
  7. /* Decision Systems Laboratory */
  8.  
  9. #include "tec.h"
  10. #include "tm.h"
  11. #include "td.h"
  12.  
  13. unsigned char *abstoptr();
  14.     
  15.  
  16. #define MAXCOL 79
  17. #define NATTR 0x0700    /* normal white on black */
  18. #define HATTR 0x0900    /* highlight */
  19. #define BLANK (defattr | 0x20)
  20. #define tchar(p) (((p) & 0x7f) | tattr)
  21. #define RLENB 160
  22.  
  23. typedef unsigned tscn[][MAXCOL+1];
  24.  
  25. #ifdef HARDINIT
  26. short tbig[] = MA80X43;
  27. short tsmall[] = MA80X25;
  28. #endif
  29.  
  30. static unsigned maxrow;
  31. static unsigned tattr;            /* attibute for char */
  32. static unsigned defattr, hltattr;
  33. static unsigned trow, tcol;
  34. static unsigned insert;
  35. static unsigned base;
  36. static tscn *screen;
  37.  
  38.  
  39. static hardinit(x)                /* hardware initialization */
  40. int *x;
  41. {
  42.     int i,n;
  43.  
  44. #ifdef HARDINIT
  45.     outportb(msr,1);
  46.     n = *x++;
  47.     outportb(xmsr,*x++);
  48.     for(i = 0; i < 14; i++) {
  49.         outportb(ptrl,i);
  50.         outportb(datal,*x++);
  51.     }
  52.     sleep(1);
  53.     outportb(msr,n);
  54. #endif
  55.     return;
  56. }
  57.  
  58.  
  59. static softinit(rows,inverse)
  60. int rows, inverse;
  61. {
  62.     maxrow = rows -1;
  63.     insert = 0;
  64.     defattr = NATTR;
  65.     hltattr = HATTR;
  66.     tattr = defattr;
  67.     if(inverse) toggle();
  68.     screen = (tscn *) abstoptr(PAGEBASE);
  69.     wipescreen();
  70.     return;
  71. }
  72.  
  73.  
  74. static toggle()
  75. {
  76.     unsigned attr = defattr;
  77.     defattr = hltattr;
  78.     hltattr = attr;
  79.     return;
  80. }
  81.  
  82.  
  83. static wipescreen()                    /* clear and home */
  84. {
  85.     unsigned row, col;
  86.     unsigned p = BLANK;
  87.     int len;
  88.     int *pos = &(*screen)[0][0];
  89.     len = (maxrow +1) * (MAXCOL +1);
  90.     while(len--) *pos++ = BLANK;
  91.     
  92. /*    for(row = 0; row <= maxrow; row++)
  93.         for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = p;
  94. */
  95.     putcurs(0,0);
  96.     return;
  97. }
  98.  
  99. static putcurs(row,col)
  100. unsigned row, col;
  101. {
  102.     static unsigned addr;
  103.     if((row > maxrow) || (col > MAXCOL)) return(ERROR);
  104.     trow = row;
  105.     tcol = col;
  106.     addr = row * 80 + col;
  107.     outportb(ptrl,14);
  108.     outportb(datal,(addr & 0xff00) >> 8);
  109.     outportb(ptrl,15);
  110.     outportb(datal,(addr & 0xff));
  111.     return(0);
  112. }
  113.  
  114.  
  115. putp(p)                        /* put one character, advance cursor */
  116. char p;
  117. {
  118.     static unsigned col;
  119.     if(insert) movmem(&(*screen)[trow][tcol],&(*screen)[trow][tcol+1],
  120.         (MAXCOL - tcol) *2);
  121. /*
  122.     if(insert) for(col = tcol; col < MAXCOL; col++)
  123.         (*screen)[trow][col+1] = (*screen)[trow][col];
  124. */
  125.     (*screen)[trow][tcol] = tchar(p);
  126.  
  127.     if(tcol < MAXCOL) putcurs(trow,tcol+1);
  128.     return;
  129. }
  130.  
  131. static wipeline()                    /* clear to end of line */
  132. {
  133.  
  134.     int len;
  135.     int *pos = &(*screen)[trow][tcol];
  136.     len = MAXCOL - tcol +1;
  137.     while(len--) *pos++ = BLANK;
  138.     return;
  139. }
  140.  
  141. static clreos()                    /* clear to end of screen */
  142. {
  143.     unsigned row, col;
  144.     row = trow;
  145.     col = tcol;
  146.     while(row <= maxrow) {
  147.         while(col <= MAXCOL) (*screen)[row][col] = BLANK;
  148.         col = 0;
  149.         row++;
  150.     }
  151.     return;
  152. }
  153.  
  154.  
  155. static delchars(n)
  156. int n;
  157. {
  158.     unsigned col;
  159.     for(col = tcol; col < MAXCOL; col++)
  160.         (*screen)[trow][col] = (*screen)[trow][col+1];
  161.     (*screen)[trow][MAXCOL] = BLANK;
  162.     return;
  163. }
  164.         
  165.  
  166. static dellines(n,bot)
  167. int n,bot;
  168. {
  169.     static unsigned char *src, *dest;
  170.     static int len;
  171.     static unsigned row, col;
  172.     
  173.     dest = &(*screen)[trow][0];
  174.     src = &(*screen)[trow+n][0];
  175.     len = (bot - trow -n +1) * RLENB;
  176.     movmem(src,dest,len);
  177.     for(row = bot -n +1; row <= bot; row++)
  178.         for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = BLANK;
  179.     putcurs(trow,0);
  180.     return;
  181. }
  182.  
  183. static inslines(n,bot)
  184. int n, bot;
  185. {
  186.     static unsigned char *src, *dest;
  187.     static int len;
  188.     static unsigned row, col;
  189.  
  190.     src = &(*screen)[trow][0];
  191.     dest =&(*screen)[trow +n][0];
  192.     len = (bot -trow -n +1) * RLENB;
  193.     movmem(src,dest,len);
  194.     for(row = trow; row < trow +n; row++)
  195.         for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = BLANK;
  196.     putcurs(trow,0);
  197.     return;
  198. }
  199.     
  200.  
  201. static
  202. INSmode(new)
  203. int new;
  204. {
  205.     insert = new;
  206. }
  207.  
  208. static
  209. HLmode(new)
  210. int new;
  211. {
  212.     if(new) tattr = hltattr;
  213.     else tattr = defattr;
  214. }
  215.  
  216.  
  217.  
  218. blanks(n)
  219. int n;
  220. {
  221.     while(n--) putp(' ');
  222.     return;
  223. }
  224.  
  225. init()
  226. {
  227.     softinit(tt.t_length,0);
  228.     base = PBASE;
  229. #ifdef HARDINIT
  230.     hardinit(tbig);
  231. #endif
  232.     return;
  233. }
  234.  
  235. reset()
  236. {
  237. }
  238.  
  239. cleanup()
  240. {
  241.     softinit(43,0);
  242. #ifdef HARDINIT
  243.     hardinit(tsmall);
  244. #endif
  245.     return;
  246. }
  247.  
  248. writechr(start,end)
  249. char *start, *end;
  250. {
  251.     static int len, plen;
  252.     static int *pos;
  253.     plen =len = end -start +1;
  254.  
  255.     pos = &(*screen)[trow][tcol];
  256.     if(insert) movmem(pos,pos +len,(MAXCOL - tcol -len +1)*2);
  257.     while(len--) *pos++ = tchar(*start++);
  258.     putcurs(trow,tcol + plen);
  259.     return;
  260. }
  261.  
  262.  
  263. Trm () {
  264.     tt.t_length = MAXROW +1;
  265.     tt.t_INSmode = INSmode;
  266.     tt.t_HLmode = HLmode;
  267.     tt.t_inslines = inslines;
  268.     tt.t_dellines = dellines;
  269.     tt.t_blanks = blanks;
  270.     tt.t_init = reset;
  271.     tt.t_cleanup = cleanup;
  272.     tt.t_wipeline = wipeline;
  273.     tt.t_wipescreen = wipescreen;
  274.     tt.t_topos = putcurs;
  275.     tt.t_reset = reset;
  276.     tt.t_delchars = delchars;
  277.     tt.t_writechars = writechr;
  278.     tt.t_window = 0;
  279.     tt.t_width = 80;
  280.     init();
  281.     return(tt.t_length);
  282. }
  283.  
  284. /* end */
  285.